<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$item=$this->plugin_setting('setting');
$return['adv']=$item['hdps'];
$return['setting']=$item;
if($_RQ['op']=='main'){
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['params']=array(
		'group_id'=>0,
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	if($_RQ['groupid']){
		$_SESSION['cmsgroupid']=$_RQ['groupid'];
	}else{
		unset($_SESSION['cmsgroupid']);
	}
	$groupspram=array('uniacid'=>$_SESSION['uniacid'],'parentid'=>0,'status'=>1);
	$return['group']=pdo_getall('jy_cmso2o_group',$groupspram,array('title','image','id'),'id');
	foreach($return['group'] as &$pv){
		$pv['ccates']=pdo_getall('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$pv['id']),array('title','id'),'id');
		foreach($pv['ccates'] as &$cv){
			$cv['scates']=pdo_getall('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$cv['id']),array('title','id'),'id');
		}
	}
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['group_id']){
		$params['group_id']=$_RQ['group_id'];
	}
	if($_RQ['ccate']){
		$params['ccate']=$_RQ['ccate'];
	}
	if($_RQ['scate']){
		$params['scate']=$_RQ['scate'];
	}
	if(!empty($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['title']=$_RQ['params']['keyword'];
	}
	if(!empty($_RQ['province']) && !$item['is_nocity']){
		$params['province']=$_RQ['province'];
		$return['params']['province']=$_RQ['params']['province'];
	}
	if(!empty($_RQ['city']) && !$item['is_nocity']){
		$params['city']=$_RQ['city'];
		$return['params']['city']=$_RQ['params']['city'];
	}
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 8;
	$total='';
	$return['status']=0;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$lat_lng=array(
		'lat'=>$_RQ['lat'],
		'lng'=>$_RQ['lng']
	);
	$list=$this->model('model')->get($parameter,$total,$lat_lng);
	if($_RQ['order']=='zhonghe'){
		paixu($list,'id','desc');
	}else{
		paixu($list,'juli','asc');
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择商户','error','/index/');
	}
	$return['detail']=pdo_get('jy_cmso2o_list',array('id'=>$id));
	$groupname=pdo_getcolumn('jy_cmso2o_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['detail']['group_id']),'title');
	$return['detail']['groupname']=$groupname;
	exi($return);
}
if($_RQ['op']=='comments'){
	$id=intval($_RQ['id']);
	if($id){
		exi('请选择商户','error','index/');
	}
	$postdata=get_postdata();
	$data=array_fields(array('type','content'),$postdata);
	$data['uid']=$_SESSION['uid'];
	$data['uniacid']=$_SESSION['uniacid'];
	$data['cid']=$id;
	$data['status']=1;
	pdo_insert('jy_cmso2o_comments',$data);
	exi('评论成功');
	}
if($_RQ['op']=='like'){
	$id=intval($_RQ['id']);
	if($id){
		exi('请选择商户','error','index/');
	}
	$like=pdo_get('jy_cmso2o_like',array('uniacid'=>$_SESSION['uniacid'],'uid'=>$_SESSION['uniacid'],'cid'=>$id));
	if(empty($like)){
		$data=array('uniacid'=>$_SESSION['uniacid'],'uid'=>$_SESSION['uniacid'],'cid'=>$id);
		pdo_insert('jy_cmso2o_like',$data);
		exi('点赞成功');
	}else{
		pdo_delete('jy_cmso2o_like',$data);
		exi('取消点赞成功');
	}
	
	}
?>